//$("head").append('<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">')


//$("#example").dataTable().fnDestroy();
if($("#example").length > 0) {
	$.fn.dataTable.ext.errMode = 'none';
}


function offcialExit() {
	$.ajax({
		"type": 'post',
		"url": url + 'Home_UserSignOut',
		'contentType': "application/x-www-form-urlencoded",
		"headers": {
			"auth-token": localStorage.getItem("official_wallet_token")
		},
		async: false,
		success: function(res) {
			window.location.href='login.html';
		}
	})
}

function GetRequest() {
	var url = location.search; //获取url中"?"符后的字串   
	var theRequest = new Object();
	if(url.indexOf("?") != -1) {
		var str = url.substr(1);
		strs = str.split("&");
		for(var i = 0; i < strs.length; i++) {
			theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
		}
	}
	return theRequest;
}
function strSplitUrl(str){
	var a = str.split("/");
	var pngStr = a[a.length-1]
	return pngStr;
}

function hasHttp(str){
	if(str.indexOf("http")!=-1){
		return str;
	}else{
		return bucketUrl+str;
	}
}
function ToLogin(res) {
	if($("#ToLogin").length == 0) {
		var string = '<div class="modal fade" id="Tologin">\
				<div class="modal-dialog">\
					<div class="modal-content">\
						<div class="modal-header">\
							<h4 class="modal-title">重新登录</h4>\
						</div>\
						<div class="modal-body">\
							 <form role="form">\
              <div class="box-body">\
                <div class="form-group">\
                	<p id="model-phone">' + res.error + '</p>\
                </div>\
              </div>\
            </form>\
						</div>\
						<div class="modal-footer">\
							<a type="button" class="btn btn-primary" href="login.html">去登录</a>\
						</div>\
					</div>\
				</div>\
			</div>';
		$("body").append(string);
	}
	$('#Tologin').modal('show');
	return false;
}

function search() {
	table.ajax.reload()
}

function reset() {
	$(".buyu_search_group input").val("");
	$(".buyu_search_group select option:first").prop("selected", "selected");
	table.ajax.reload()
}

function clearRangeTime(x) {
	$(x).prev().val('')
}

function toThousands(num) {
	var result = [],
		counter = 0;
	num = (num || 0).toString().split('.');
	console.log(num)
	for(var j = num[0].length - 1; j >= 0; j--) {
		counter++;
		result.unshift(num[0][j]);
		if(!(counter % 3) && j != 0) {
			result.unshift(',');
		}
	}
	return result.join('') + "." + num[1];
}

function renderData(Json) {
	var data = {}
	$.each(Json, function(index, item) {
		if(item.value != "") {
			if(item.type == "time") {
				data[index] = item.value + ":00";
			} else {
				data[index] = item.value;
			}
		}
	})
	return data
}
//
//	admin
//
function adminState(type) {
	//1：正常  2：冻结   3：删除
	var str = "";
	switch(type) {
		case 1:
			str = '<small class="label label-success">&nbsp;正常&nbsp;</small>';
			break;
		case 2:
			str = '<small class="label label-default">&nbsp;冻结&nbsp;</small>';
			break;
		case 3:
			str = '<small class="label label-danger">&nbsp;删除&nbsp;</small>';
			break;
		default:
			str = "";
	}
	return str;
}

//
//  user
//
function userState(type) {
	//1：正常  2：拉黑   3：删除
	var str = "";
	switch(type) {
		case 1:
			str = '<small class="label label-success">&nbsp;正常&nbsp;</small>';
			break;
		case 2:
			str = '<small class="label label-default">&nbsp;拉黑&nbsp;</small>';
			break;
		default:
			str = "";
	}
	return str;
}

//
//交易
//
function dealState(type) {
	//0：进行中   1：成功    2：失败
	var str = "";
	switch(type) {
		case 0:
			str = '<small class="label label-primary">&nbsp;进行中&nbsp;</small>';
			break;
		case 1:
			str = '<small class="label label-success">&nbsp;成功&nbsp;</small>';
			break;
		case 2:
			str = '<small class="label label-danger">&nbsp;失败&nbsp;</small>';
			break;
		default:
			str = "";
	}
	return str;
}

//api
function apiState(type) {
	//0：审核中   1：通过    2：拒绝
	var str = "";
	switch(type) {
		case 0:
			str = '<small class="label label-primary">&nbsp;审核中&nbsp;</small>';
			break;
		case 1:
			str = '<small class="label label-success">&nbsp;通过&nbsp;</small>';
			break;
		case 2:
			str = '<small class="label label-danger">&nbsp;拒绝&nbsp;</small>';
			break;
		default:
			str = "";
	}
	return str;
}

// 平台
function PState(type) {
	//1：ios    2：android
	var str = "";
	switch(type) {
		case 1:
			str = 'IOS'; //'<small class="label label-primary">&nbsp;&nbsp;</small>';
			break;
		case 2:
			str = "安卓"; //'<small class="label label-success">&nbsp;安卓&nbsp;</small>';
			break;
		default:
			str = "";
	}
	return str;
}